import java.io.IOException;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

public class SplashScreen extends Canvas implements Runnable {
	
	private static final long CDTIME = 1000;
	
	private int width, height;
	private Image avatar;
	private Display display;
	private Displayable next;
	
	public SplashScreen(Display display) {
		this.display = display;
		setFullScreenMode(true);
		width = getWidth();
		height = getHeight();
		
		try {
			avatar = Image.createImage("/avatar.png");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void setNextScreen(Displayable next) {
		this.next = next;
	}
	
	protected void paint(Graphics g) {
		g.setColor(0x000000);
		g.fillRect(0, 0, width, height);
		g.drawImage(avatar, width / 2, height / 2, 3);
	}
	
	public void run() {
		try {
			Thread.sleep(CDTIME);
			display.setCurrent(next);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	
	protected void showNotify() {
		new Thread(this).start();
	}

}
